<?php 

include "../function/function.php";
// $arr=[2,3,5,4,1];
// var_dump($arr);


$arr=[2,3,5,4,1];
function run(){
	global $arr;
	$a=[];
	for ($i=1; $i <= count($arr) ; $i++) { 
		array_push($a,$arr[count($arr)-$i]);
	};
	return $a;
};

var_dump(run());



$g=array("name"=>"Tom","age"=>"18","from"=>"china","tall"=>"190","sex"=>"男");
// var_dump($g);
// 键与值对换位置
function huan($g){
	$b=[];
	foreach ($g as $key => $value) {
		$b[ $value ]=$key;

	}
	return  $b;
};
$res=huan($g);
var_dump($res);





$arr = array(
	array(
		'num'=>'20160501',
		'name'=>'小王',
		'score'=>'80'
		),
	array(
		'num'=>'20160506',
		'name'=>'小李',
		'score'=>'75'
		),
	array(
		'num'=>'20160503',
		'name'=>'小张',
		'score'=>'95'
		),
	array(
		'num'=>'20160504',
		'name'=>'小马',
		'score'=>'75'
		),
	array(
		'num'=>'20160505',
		'name'=>'小明',
		'score'=>'90'
		)
	);
// 分数排序
function lis($arr){
	$a=[];
	foreach ($arr as $key => $value) {
		$a[$value['score'].$value["num"]]=$value;
		// 后面的score是$arr的值的一部分，所以用$value筛选出键score
		// $value['score']的结果是二位数组中的值
		krsort($a);
	};
	

	return $a;
};

$res =lis($arr);
var_dump($res);










$c = array(
	array(
		'num'=>'20160501',
		'name'=>'小王',
		'score'=>'80',
		'class'=>'1'
		),
	array(
		'num'=>'20160506',
		'name'=>'小李',
		'score'=>'75',
		'class'=>'2'
		),
	array(
		'num'=>'20160503',
		'name'=>'小张',
		'score'=>'95',
		'class'=>'1'
		),
	array(
		'num'=>'20160504',
		'name'=>'小马',
		'score'=>'75',
		'class'=>'1'
		),
	array(
		'num'=>'20160505',
		'name'=>'小明',
		'score'=>'90',
		'class'=>'2'
		)
	);
求班级平均分
function ping($c){
	$a=[];
	foreach ($c as $key => $value) {
		$a[$value["class"]][]=$value["score"];

	};
	foreach ($a as $key => $value) {
	 echo 	array_sum($value)/count($value);
	 echo "<br>";
	};

	return $a;
};
$res=ping($c);
var_dump($res);

























 ?>